﻿Imports System.Data.SqlClient

Public Class frmOtrosNuevos
    Dim existenCargos As Boolean
    Dim Bitacora As New clsActividad
    Private Sub frmOtrosNuevos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CheckBox1.Checked = False

        Me.dgCargos.Rows.Clear()
        existenCargos = False

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "select NombreCompleto,fecha,tiempo,tipo,descuento,capturo,monto,motivo From OtrosCargos O INNER JOIN Empleados E " & _
        " ON O.idempleado=E.idempleado WHERE reportado='No' order by fecha"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim tipo As String
        Dim tiempo As String
        Dim fecha As Date

        Do While rdBuscar.Read()
            existenCargos = True
            tipo = rdBuscar("Tipo").ToString.Trim
            If tipo = "Semanal" Then
                tipo = "Semana(s)"
            ElseIf tipo = "Diario" Then
                tipo = "Dia(s)"
            Else

                tipo = "Catorcena(s)"
            End If
            tiempo = rdBuscar("tiempo") & " " & tipo
            fecha = rdBuscar("Fecha")
            Me.dgCargos.Rows.Add(rdBuscar("NombreCompleto"), fecha.Day & "/" & fecha.Month & "/" & fecha.Year, rdBuscar("motivo"), rdBuscar("monto"), tiempo, rdBuscar("descuento"), rdBuscar("Capturo"))
        Loop

        If existenCargos = False Then
            Me.Close()

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub btnAbrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbrir.Click
        ToExcel(Me.dgCargos, "Relacion de nuevos cargos varios al " & Now())
    End Sub

    Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
        If Me.CheckBox1.Checked = True Then
            Call SetSqlCitra("Update OtrosCargos set reportado='Si' where reportado='No'")
            Bitacora.RegistraActividad("Revisó las notificaciones de cargos varios nuevos")

            Me.Close()
        Else
            Me.Close()
        End If
    End Sub
End Class